package chapter2.sorting;

import java.util.Comparator;

/**
 * Created by wsy on 2017/12/2 0002.
 */
public class C2_1_1Example {
    public static void sort(Comparable[] a) { /* See Algorithms 2.1, 2.2, 2.3, 2.4, 2.5, or 2.7. */ }

    public static boolean less(Comparable v, Comparable w) {
        return v.compareTo(w) < 0;
    }

    public static void exch(Comparable[] a, int i, int j) {
        Comparable t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void show(Comparable[] a) { // Print the array, on a single line.
        for (int i = 0; i < a.length; i++)
            System.out.print(a[i] + " ");
        System.out.println();
    }

    public static boolean isSorted(Comparable[] a) { // Test whether the array entries are in order.
        for (int i = 1; i < a.length; i++)
            if (less(a[i], a[i - 1])) return false;
        return true;
    }

    public static void main(String[] args) { // Read strings from standard input, sort them, and print.
//        String[] a = In.readStrings();
//        sort(a);
//        assert isSorted(a);
//        show(a);
        int n =20;
        Integer[] a = new Integer[n];
        for(int i = 0; i < n ; i ++){
            a[i] = (int)(Math.random()*1000);
        }
        A2_1SelectionSort.sort(a);
        show(a);
    }
}
